package pld.car.action;

import java.util.*;

import pld.car.bean.News;

public class NewsAction extends BaseAction {

	private List<Object> KYXXList;

	private List<Object> HYDTList;

	private List<Object> newsList;

	private int rowCountPerPageForDisplay;

	private int maxPageInBar;

	private String pageBar;

	private int pageNo;

	private String result;

	/* 读取一条新闻所需的变量=================================================== */
	private int newsID;

	private News KYXXContent;
	private News HYDTContent;

	public NewsAction() {
		System.out.println("NewsAction init!");
	}

	// 初始化页面的时候需要初始化的一些设定值
	public void loadOptions() {
		// 获取每页显示的记录数,在页面展示部分
		String setValue = this.getSettingsService().getOption("Options", "rowCountPerPageForDisplay");
		this.setRowCountPerPageForDisplay(Integer.parseInt(setValue));
		// 分页工具条最多显示的页面数
		setValue = this.getSettingsService().getOption("Options", "maxPageInBar");
		this.setMaxPageInBar(Integer.parseInt(setValue));
	}

	// 按条件查询，得到客运信息列表，为客运信息页面服务
	public String queryKYXXTitleForDisplay() {
		loadOptions();
		// 总共的记录数
		int count = this.getNewsService().getKYXXCount();
		// 初始化分页工具栏的参数
		this.getPageService().initParams(count, this.pageNo, this.rowCountPerPageForDisplay, this.maxPageInBar);
		// 生成分页工具栏
		this.setPageBar(this.getPageService().createPageBar());
		// 根据输入的sql查询当前页的记录
		this.setNewsList(this.getNewsService().getKYXXTitle(this.getPageService().getFirstItemThisPage(), this.rowCountPerPageForDisplay));
		return "success";
	}

	// 按条件查询，得到行业动态列表，为行业动态页面服务
	public String queryHYDTTitleForDisplay() {
		loadOptions();
		// 总共的记录数
		int count = this.getNewsService().getHYDTCount();
		// 初始化分页工具栏的参数
		this.getPageService().initParams(count, this.pageNo, this.rowCountPerPageForDisplay, this.maxPageInBar);
		// 生成分页工具栏
		this.setPageBar(this.getPageService().createPageBar());
		// 根据输入的sql查询当前页的记录
		this.setNewsList(this.getNewsService().getHYDTTitle(this.getPageService().getFirstItemThisPage(), this.rowCountPerPageForDisplay));
		return "success";
	}

	// 获取指定数量客运信息的标题和时间
	public String queryKYXXTitle() {
		this.setKYXXList(this.getNewsService().getKYXXTitle(0, 14));
		return "success";
	}

	// 获取指定数量 行业动态 的标题和时间
	public String queryHYDTTitle() {
		this.setHYDTList(this.getNewsService().getHYDTTitle(0, 14));
		return "success";
	}

	// 根据ID查询对应的客运信息
	public String queryKYXXContent() {
		this.setKYXXContent(this.getNewsService().findNewsByID(newsID));
		return "success";
	}

	// 根据ID查询对应的行业动态
	public String queryHYDTContent() {
		this.setHYDTContent(this.getNewsService().findNewsByID(newsID));
		return "success";
	}

	public List<Object> getKYXXList() {
		return KYXXList;
	}

	public void setKYXXList(List<Object> kYXXList) {
		KYXXList = kYXXList;
	}

	public List<Object> getHYDTList() {
		return HYDTList;
	}

	public void setHYDTList(List<Object> hYDTList) {
		HYDTList = hYDTList;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public int getMaxPageInBar() {
		return maxPageInBar;
	}

	public void setMaxPageInBar(int maxPageInBar) {
		this.maxPageInBar = maxPageInBar;
	}

	public String getPageBar() {
		return pageBar;
	}

	public void setPageBar(String pageBar) {
		this.pageBar = pageBar;
	}

	public List<Object> getNewsList() {
		return newsList;
	}

	public void setNewsList(List<Object> newsList) {
		this.newsList = newsList;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getRowCountPerPageForDisplay() {
		return rowCountPerPageForDisplay;
	}

	public void setRowCountPerPageForDisplay(int rowCountPerPageForDisplay) {
		this.rowCountPerPageForDisplay = rowCountPerPageForDisplay;
	}

	public int getNewsID() {
		return newsID;
	}

	public void setNewsID(int newsID) {
		this.newsID = newsID;
	}

	public News getKYXXContent() {
		return KYXXContent;
	}

	public void setKYXXContent(News kYXXContent) {
		KYXXContent = kYXXContent;
	}

	public News getHYDTContent() {
		return HYDTContent;
	}

	public void setHYDTContent(News hYDTContent) {
		HYDTContent = hYDTContent;
	}

}
